require "ship"

module Game

  # cell of game field
  class Cell
    def initialize(x,y)
      @x,@y = x,y
      @ship = nil
    end
  end

  # main class for player battlefield
  class Battlefield
    def initialize(user,width=10,height=10)
      @user = user
      @ships = []

      # initialize cells
      @cells = []
      width.times do |x|
        col = []
        height.times do |y|
          cells << Cell.new(x,y)
        end
        @cells << col
      end
    end

    # add new ship and fills cells with ship data
    def add_ship(ship)
      if ship.blank?
        @ships << ship

        # fill cells with ships
        ship.cells.each do |cell|
          @cells[cell.x][cell.y].ship = ship
        end
      end
    end
  end
end
